package com.thread.thread.Lua;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LuaController {
	@Autowired
	RedisLock redisLock;
	@GetMapping(value = "/lua")
	public void luaTest()  throws Exception{
		Thread[] threads=new Thread[10];

		for(int i=0;i<threads.length;i++){

			threads[i]= new Thread() {
				@Override
				public void run() {
					try {

						if(redisLock.lock("caicaiLock","1")){
							System.out.println("我得到锁"+Thread.currentThread().getName());
						}else{
							System.out.println("未得到锁"+Thread.currentThread().getName());

						}
					} catch (Exception e) {
						e.printStackTrace();
					}finally {

					}

				}
			};
			threads[i].setName("线程"+i);
		}

		for(int i=0;i<threads.length;i++){
			threads[i].start();
		}
		for(int i=0;i<threads.length;i++){
			threads[i].join();
		}
	}

}
